package com.qianfeng.vhly.youshare;

/**
 * Created with IntelliJ IDEA.
 * User: vhly[FR]
 * Date: 15/2/7
 * Email: vhly@163.com
 */

import com.qianfeng.vhly.youshare.model.Category;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * 数据存储区，单例模式访问。
 */
public class DataStorage {
    private static DataStorage ourInstance;

    public static DataStorage getInstance() {
        if (ourInstance == null) {
            ourInstance = new DataStorage();
        }
        return ourInstance;
    }

    /**
     * 存储应用程序中，商城部分的分类信息
     */
    private HashMap<String, Category> storeCategories;

    private DataStorage() {
        storeCategories = new LinkedHashMap<String, Category>();
    }

    public void addCategory(Category category) {
        if (category != null) {
            String cid = category.getId();
            if (cid != null) {
                storeCategories.put(cid, category);
            }
        }
    }

    public Category getCategory(String cid) {
        Category ret = null;

        if (cid != null) {
            if(storeCategories.containsKey(cid)){
                ret = storeCategories.get(cid);
            }
        }

        return ret;
    }
}
